package com.education.expenses.assembler;

import com.education.expenses.common.dto.UserDTO;
import com.education.expenses.entity.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * User: alpoloz
 * Date: 7/11/12
 * Time: 6:47 PM
 */
@Component
public class UserAssembler extends GenericAssembler<User, UserDTO> {

    public UserDetails convertUserToUserDetails(User user) {
        ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new SimpleGrantedAuthority(user.getRole().name()));
        return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), true, true, true, true, authorities);
    }
}
